package com.brunogb.pages.server.model;

import java.io.Serializable;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Page extends BaseModel implements Serializable{

	private static final long serialVersionUID = 2035561719994222277L;
	
	@Persistent
	@PrimaryKey
	private Key key;
	
	@Persistent
	private String pageName;
	
	private Exception pageException;
	
	private boolean newPage = false;
	
	public Page() {
		newPage = true;
		pageName = "New Page";
	}
	
	public Page(String page) {
		pageName = page;
		key = BaseModel.creatKey(this.getClass(), pageName); 
	}
	
	public Key getKey(){
		return key;
	}
	
	public void setPageError(Exception pageException) {
		this.pageException = pageException;
	}

	public Exception getPageError() {
		return pageException;
	}
	
	public boolean hasError(){
		return pageException != null;
	}
	
	public String getPageName(){
		return pageName;
	}
	
	public void setPageName(String pageName){
		this.pageName = pageName;
		this.key = BaseModel.creatKey(this.getClass(), this.pageName);
	}
	
	public boolean isNewPage(){
		return newPage;
	}
	
}
